package com.testdemo.common.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.testdemo.common.utils.CommonUtil;


/**
 *  自定义的StatusBar,用来实现和状态栏同高度的View
 *
 * Created by thinkpad on 2018/4/3.
 */

public class StatusBarView extends View {
    private int viewHeight;

    public StatusBarView(Context context) {
        super(context);
    }

    public StatusBarView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);

//        if (widthMode == MeasureSpec.AT_MOST || widthMode == MeasureSpec.UNSPECIFIED) {
//            viewWidth = VIEW_DEF_WIDTH;
//        } else {
//            viewWidth = widthSize;
//        }

        if (heightMode == MeasureSpec.AT_MOST || heightMode == MeasureSpec.UNSPECIFIED) {
            viewHeight = CommonUtil.getStatusBarHeight();
        } else {
            viewHeight = heightSize;
        }

        setMeasuredDimension(widthSize, viewHeight);
    }
}
